import { suggestionResponse, SuggestionResultResponse } from '@/types/data'
import { RootThunkAction } from '@/types/store'
import http from '@/utils/http'
export const getSuggestion = (value: string): RootThunkAction => {
  return async (dispatch) => {
    const res = await http.get<suggestionResponse>('/suggestion', {
      params: {
        q: value,
      },
    })
    console.log(res, '123')

    dispatch({ type: 'search/suggestion', payload: res.data.data.options })
  }
}
//文本框为空时 。清空数据
export const clearSuggestion = () => ({ type: 'search/clearSuggestion' })
//搜索结果
export const getSuggestionResult = (query: string): RootThunkAction => {
  return async (dispatch) => {
    const res = await http.get<SuggestionResultResponse>('/search', {
      params: {
        page: 1,
        per_page: 10,
        q: query,
      },
    })
    dispatch({ type: 'search/getSuggestionResult', payload: res.data.data })
  }
}
